package daoimpl;

import dao.AdminDao;
import javabean.Admin;
import util.JDBCUtil;

import java.util.ArrayList;

/**
 * packageName com.mt.bms.daoimpl
 *
 * @author Administrator
 * @version 1.0
 * @className AdminDaoImpl (此处以class为例)
 * @date 2024/8/2
 * @description
 */
public class AdminDaoImpl implements AdminDao<Admin> {
    @Override
    public int insert(Admin admin) {
        String sql = "insert into admin(username, password, name, email, detailed) value(?, ?, ?, ?, ?)";
        return JDBCUtil.dml(sql, admin.getUserName(), admin.getPassWord(), admin.getName(), admin.getEmail(), admin.getDetailed());
    }

    @Override
    public ArrayList<Admin> selectByUsernameAndPassword(String username, String password) {
        String sql = "select * from admin where username = ? and password = ?";
        return JDBCUtil.dql(sql, Admin.class, username, password);
    }

    @Override
    public int deleteById(int id) {
        String sql = "delete from admin where id = ?";
        return JDBCUtil.dml(sql, id);
    }

    @Override
    public int deleteByUsername(String username) {
        String sql = "select * from admin where username = ?";
        return JDBCUtil.dml(sql, username);
    }

    @Override
    public int updatePasswordById(int id, String password) {
        String sql = "update admin set password = ? where id = ?";
        return JDBCUtil.dml(sql, password, id);
    }

    @Override
    public ArrayList<Admin> selectAll() {
        String sql = "select * from admin";
        return JDBCUtil.dql(sql, Admin.class);
    }

    @Override
    public ArrayList<Admin> selectAdminByUsername(String username) {
        String sql = "select * from admin where username = ?";
        return JDBCUtil.dql(sql, Admin.class, username);
    }
}